package com.siwei.apply.controller;

import com.siwei.apply.domain.YdbpData;
import com.siwei.apply.domain.vo.YdbpDataFilterVo;
import com.siwei.apply.domain.vo.YdbpDataUpdateVo;
import com.siwei.apply.domain.vo.YdbpDataVo;
import com.siwei.apply.service.YdbpDataService;
import com.siwei.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 用地报批（批次）数据集
 */
@RestController
@RequestMapping("/ydbpData")
public class YdbpDataController {
    @Autowired
    private YdbpDataService ydbpDataService;

    /**
     * 新增数据
     *
     * @param ydbpDataVo
     * @return
     */
    @PostMapping("")
    public R<String> add(@RequestBody YdbpDataVo ydbpDataVo) {
        try {
            String id = ydbpDataService.add(ydbpDataVo);
            return R.ok(id);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    /**
     * 获取数据详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<YdbpData> getById(@PathVariable String id) {
        try {
            YdbpData data = ydbpDataService.getById(id);
            return R.ok(data);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    /**
     * 获取数据列表
     *
     * @param filterVo
     * @return
     */
    @PostMapping("/list")
    public R<Map<String, Object>> getList(@RequestBody YdbpDataFilterVo filterVo) {
        try {
            Map<String, Object> result = ydbpDataService.getList(filterVo);
            return R.ok(result);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    /**
     * 修改数据
     */
    @PutMapping("")
    public R<Void> update(@RequestBody YdbpDataUpdateVo ydbpDataVo) {
        try {
            ydbpDataService.update(ydbpDataVo);
            return R.ok();
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }
}
